<!-- saved from url=(0026)/test.html -->
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <title>骡窝窝问答,解决旅行问题,基于旅游的问答分享平台</title>
    <meta name="viewport"
          content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no,minimal-ui,viewport-fit=cover">
    <meta name="format-detection" content="telephone=no,address=no">
    <link href="/css/mobile+css+head_mobile+css+ui^YVw^1526627473.css" rel="stylesheet" type="text/css">
    <link href="/css/new_ask2016.css" rel="stylesheet" type="text/css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/plugins/jquery-form/jquery.form.js"></script>
    <script src="/js/plugins/jrender/jrender.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog/dialog.css"/>
    <script src="/js/plugins/dialog/dialog.min.js"></script>
    <script src="/js/common.js"></script>



</head>
<body>
<div id="pos38"></div>
<header class="MfwHead ">
    <div class="LBtn"><a class="btn back"
                         href="javascript:void(window.history.length &gt; 1 ? window.history.back() : document.location.href=&#39;http://m.mafengwo.cn&#39;)"
                         id="_j_top_history_back"></a>
    </div>
    <div class="CBtn"><h1>骡窝窝问答</h1></div>
    <div class="RBtn">
    </div>
</header>
<div class="question">
    <section class="ans-list a-list" render-loop="list">
        <ul class="_j_pager_box">
            <li>
                <a render-key="list.id" render-fun="handle">
                    <h2 render-html="list.title"></h2>
                    <div class="user-img clearfix" data-uid="46376914">
                        <p>
                            <img render-src="list.author.headImgUrl">
                        </p>
                        <span render-html="list.author.nickName"></span>
                        <span render-html="list.questionTime"></span>
                    </div>
                </a>
                <div class="ans-nr">
                    <div class="clearfix">
                        <p render-html="list.questionContent"></p>
                    </div>

                    <div class="clearfix">
                        <span class="fl-r">
                            <a render-key="list.id" render-fun="handle"><b>回答:<span style="color: #ff8a00" render-html="list.answerNum"/></b>
                            <b>评论:<span style="color: #ff8a00" render-html="list.commentNum"/></b></a>
                        </span>
                    </div>
                </div>
            </li>
        </ul>
    </section>
</div>


<a href="mine/ask.html" class="btn-que"><i></i>
    我要提问
</a>

<script>
    $(function () {

        //全局变量
        var currentPage;//当前页
        var pages;//总页数
        var totalData;//返回回来的数据

        $.get("/questions", function (data) {
            renderView(data);
            currentPage = data.pageNum;
            pages = data.pages;
            totalData = data.list;
        });

        //当屏幕滚动到最底部时执行函数
        $(window).scroll(function () {
            //判断是否到底部
            if (isEnd()) {
                //判断是否有下一页
                if (currentPage < pages) {
                    //设置当前页+1,并且发送ajax请求获取下一页数据
                    currentPage++;
                    $.get("/questions", {currentPage: currentPage, pageSize: 3}, function (data) {
                        //把返回的数据渲染到界面
                        //返回的数据中,只有翻页后的数据,没有当前页中的数据,直接渲染就没有了
                        //原来的数据+当前的数据,一起渲染
                        //不能直接把数组传入,因为底层渲染需要一个list属性
                        $.merge(totalData, data.list);
                        renderView({list: totalData});
                    });
                }
                /*else {
                     $(document).dialog({
                       type: "notice",
                       infoText: "已经到达底部了",
                       autoClose: 1500,
                       position: "bottom"
                 });
               }*/
            }
        });

        //保存评论内容,动态获取
        $(".question").on("click",".xxx",function () {
            var id = $(this).data("id");
            $(".clearfix input[name='questionId']").val(id);
            $("#question_operator").ajaxSubmit();
        });
    });

    //判断是否滚到底部
    function isEnd() {
        //溢出高度+屏幕高度 = 网页高度
        return $(window).height() + $(window).scrollTop() >= $(document).height();
    }

    function renderView(data) {
        $(".question").renderValues(data, {
            //属性名就是函数的名称
            handle: function (ele, value) {
                //动态渲染a标签
                $(ele).attr("href", "/answer.html?id=" + value);
            },
            idHandler:function (ele,value) {
                $(ele).attr("data-id",value);
            }
        });
    }

</script>
</body>
</html>